from sqlalchemy import func

from ...db import models as db
from ...db.util import transaction
from ..base import BaseProcessor
from ..util import get_parameter


class SpiritProcessor(BaseProcessor):
    """球风榜/spirits
    """
    @transaction()
    def read(self, *args, **kwargs):
        return self.query(*args, **kwargs)

    def query(self, *args, **kwargs):
        """Param

        args:( None )
        kwargs:{ leagueid }
        """
        rank = func.rank().over(order_by=db.Spirit.points.desc()).label('rank')
        q = self.dbh.query(db.Spirit)\
                    .add_columns(rank)
        if kwargs:
            q = q.filter_by(**kwargs)
        return q.all()
